home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 May: Tool Chest / Dev.CD May 97 TC.toast / Sample Code / Snippets / Toolbox / ItemHider / Turbo / SingleHider / SingleHider.Pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-15  |  3.7 KB  |  141 lines  |  [TEXT/TPAS]

  1. PROGRAM SingleHider;
  2.  
  3. {$R SingleHider.Rsrc}
  4. {$U-}
  5.  
  6. USES Memtypes,QuickDraw,OSIntf,ToolIntf,PackIntf;
  7.  
  8. CONST
  9.    itemOK =       3;
  10.    itemCancel =   4;
  11.    itemStat1 =    1;
  12.    itemEdit1 =    2;
  13.    itemHider =    5;
  14.    itemHideIt =   6;
  15.    itemMax =      6;
  16. VAR
  17.    ihDialog:   DialogPtr;
  18.    itemHit:    INTEGER;
  19.    theType:    INTEGER;
  20.    theHdl:     Handle;
  21.    theBox:     Rect;
  22.    oldEditField:  INTEGER;
  23.    hidden:     BOOLEAN;
  24.    OnlyOne:    BOOLEAN;
  25.  
  26.  
  27. PROCEDURE MyDrawItem(dlg: DialogPtr; theItem: INTEGER);
  28. VAR
  29.    iType:   INTEGER;
  30.    iBox:    Rect;
  31.    iHdl:    Handle;
  32.    iIndex:  INTEGER;
  33.  
  34. BEGIN
  35.    GetDItem(dlg, theItem, iType, iHdl, iBox);
  36.    IF hidden THEN BEGIN
  37.       PenMode(notPatBic);
  38.       PenPat(gray);
  39.       BackPat(gray);
  40.       PaintRect(iBox);
  41.       FrameRect(iBox);
  42.       
  43.       PenMode(patCopy);
  44.       PenPat(black);
  45.       BackPat(white);
  46.       PenNormal;
  47.    END;
  48. END;
  49.  
  50.  
  51. PROCEDURE HideEditItem(theDialog: DialogPtr; theItem: INTEGER);
  52. VAR
  53.    iIndex:  INTEGER;
  54. BEGIN
  55.    OnlyOne := FALSE;
  56.  
  57.    (* Get the item information. *)
  58.    GetDItem(theDialog, theItem, theType, theHdl, theBox);
  59.    
  60.       (* Is theItem the current editText item?           *)
  61.       IF DialogPeek(theDialog)^.EditField + 1 = theItem THEN BEGIN
  62.       (* It is, so now we find the next editText item    *)
  63.       (* in the item list.  Start with the one we are on.*)
  64.       iIndex := theItem;
  65.       REPEAT
  66.          (* Increment to the next item, and make sure we *)
  67.          (* don't run off the end of the item list.      *)
  68.          iIndex := iIndex + 1;
  69.          IF iIndex > itemMax THEN iIndex := 1;
  70.          
  71.          (* If we're back to theItem, then we don't have *)
  72.          (* another editText item.  In this case, we'll  *)
  73.          (* just set the EditField to -1 to tell the     *)
  74.          (* Dialog Manager that we don't have _any_      *)
  75.          (* editText items.                              *)
  76.          IF iIndex = theItem THEN BEGIN
  77.             (* Set a flag, so ShowEditItem knows to set  *)
  78.             (* this back.                                *)
  79.             OnlyOne := TRUE;
  80.          END ELSE
  81.             GetDItem(theDialog, iIndex, theType, theHdl, theBox);
  82.       UNTIL (OnlyOne OR (theType = editText));
  83.       
  84.       IF (NOT OnlyOne) THEN
  85.          SelIText(theDialog, iIndex, 0, 0);
  86.    END;
  87.    GetDItem(theDialog, theItem, theType, theHdl, theBox);
  88.    SetDItem(theDialog, theItem, statText, theHdl, theBox);
  89.    oldEditField := DialogPeek(theDialog)^.EditField;
  90.    DialogPeek(theDialog)^.EditField := -1;
  91.    DrawDialog(theDialog);
  92. END;
  93.  
  94.  
  95. PROCEDURE ShowEditItem(theDialog: DialogPtr; theItem: INTEGER);
  96. BEGIN
  97.    GetDItem(theDialog, theItem, theType, theHdl, theBox);
  98.    SetDItem(theDialog, theItem, editText, theHdl, theBox);
  99.    
  100.    IF OnlyOne THEN
  101.       DialogPeek(theDialog)^.EditField := oldEditField;
  102.  
  103.    DrawDialog(theDialog);
  104. END;
  105.  
  106.  
  107. BEGIN {main program}
  108.    InitGraf (@thePort);          {the big five inits}
  109.    InitFonts;
  110.    InitWindows;
  111.    TEInit;
  112.    InitDialogs (nil);
  113.  
  114.    hidden := FALSE;
  115.  
  116.    ihDialog := GetNewDialog(128, NIL, WindowPtr(-1));
  117.    GetDItem(ihDialog, itemHider, theType, theHdl, theBox);
  118.    SetDItem(ihDialog, itemHider, theType, @MyDrawItem, theBox);
  119.    ShowWindow(ihDialog);
  120.    
  121.    itemHit := 0;
  122.    WHILE ((itemHit <> itemOK) AND (itemHit <> itemCancel)) DO BEGIN
  123.       ModalDialog(nil, itemHit);
  124.       CASE itemHit OF
  125.          itemHideIt: BEGIN
  126.             GetDItem(ihDialog, itemHit, theType, theHdl, theBox);
  127.             hidden := NOT hidden;
  128.             IF hidden THEN BEGIN
  129.                SetCtlValue(ControlHandle(theHdl), 1);
  130.                HideEditItem(ihDialog, itemEdit1);
  131.             END ELSE BEGIN
  132.                SetCtlValue(ControlHandle(theHdl), 0);
  133.                ShowEditItem(ihDialog, itemEdit1);
  134.             END;
  135.          END;
  136.       END;
  137.    END;
  138.  
  139.    DisposDialog(ihDialog);
  140. END.
  141.